package DMDE.model.tests;

import static org.junit.Assert.*;

import java.util.List;

import main.java.DMDE.model.Attribute;
import main.java.DMDE.model.Modifier;
import main.java.DMDE.model.Type;
import main.java.DMDE.model.Visibility;

import org.junit.Before;
import org.junit.Test;

public class AttributeTestCase {

	private static final String TEST_ATTRIB_TYPE = "int";
	private static final String TEST_ATTRIB_NAME = "number";

	private Attribute attribute;
	private Type type;

	@Before
	public void setUp() {
		type = new Type(TEST_ATTRIB_TYPE);
		attribute = new Attribute(TEST_ATTRIB_NAME, type);
	}

	@Test
	public void testName() {
		assertEquals(TEST_ATTRIB_NAME, attribute.getName());
		attribute.setName("newName");
		assertEquals("newName", attribute.getName());
	}

	@Test
	public void testType() {
		assertEquals(type, attribute.getType());
		Type newType = new Type("String");
		attribute.setType(newType);
		assertEquals(newType, attribute.getType());
	}

	@Test
	public void testSameAttribute() {
		attribute.setName("name");
		Attribute attribute2 = new Attribute("name", type);
		assertTrue(attribute.is(attribute2));
	}

	@Test
	public void testVisibility() {
		attribute.setVisibility(Visibility.PUBLIC);
		assertEquals(Visibility.PUBLIC, attribute.getVisibility());
	}

	@Test
	public void testAddModifier() {
		attribute.addModifier(Modifier.ABSTRACT);
		List<Modifier> modifiers = attribute.getModifiers();
		assertEquals(Modifier.ABSTRACT, modifiers.get(0));
	}

	@Test
	public void testRepeatedModifier() {
		attribute.addModifier(Modifier.ABSTRACT);
		attribute.addModifier(Modifier.ABSTRACT);
		List<Modifier> modifiers = attribute.getModifiers();
		assertEquals(1, modifiers.size());
	}

}
